/**
 * Created by Administrator on 2016/12/28 0028.
 */
// var ur = 'http://sp.tunnel.qydev.com/xmsd/';// 打包

// 上线地址
var ur = 'http://xiaomashidai.com/xmsd/';

// var ur = 'http://127.0.0.1:8080/xmsd/';

var ERROR_OK = 'S002';

function href(a, b, obj) {
    obj = obj || {};
    obj.idd = b;
    mui.openWindow({
        url: a,
        id: b,
        styles: {
            top: '', // 新页面顶部位置
            bottom: '', // 新页面底部位置
        },
        show: "pop-in",
        extras: obj,
        createNew: false, // 是否重复创建同样id的webview，默认为false:不重复创建，直接显示
    })
}

/**
 * create by wensimin
 * 全局处理过期登录
 */
// todo
$(document).ajaxComplete(function (event, request, settings) {
    try {
        var json = JSON.parse(request.responseText);
        if (json.meta.code == 'E001') {
            // localStorage.setItem('voice', 'true');
            mui.toast('登录已过期,请重新登录');
            href(ur + 'web/html/enter.html');
        }
    } catch (e) {

    } finally {
        $('.loadingGif').remove();
    }
});
/**
 * create by wensimin
 * 全局开启ajax load
 */
// $(document).ajaxStart(function (event, request, settings) {
$(document).ajaxSend(function (event, request, settings) {
    $('body').append('<div class="loadingGif"></div>');
});

/*//全局设置响应头的token
 $.ajaxSettings.beforeSend = function(xhr,request){
 request.headers ={
 'X-Token':localStorage.token
 }
 }*/

// 转义富文本
function HTMLDecode(text) {
    var temp = document.createElement("div");
    temp.innerHTML = text;
    var output = temp.innerText || temp.textContent;
    temp = null;
    return output;
}

// 获取url参数
function urlParse() {
    var url = window.location.search;
    var obj = {};
    var reg = /[?&][^?&]+=[^?&]+/g;
    var arr = url.match(reg);
    if (arr) {
        arr.forEach(function (item) {
            var tempArr = item.substring(1).split('=');
            var key = decodeURIComponent(tempArr[0]);
            var val = decodeURIComponent(tempArr[1]);
            obj[key] = val;
        });
    }
    return obj;
}